package com.ruoyi.operation.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.operation.domain.bo.DailyTaskBo;
import com.ruoyi.operation.domain.vo.DailyTaskVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.operation.domain.vo.TItdutytaskListVo;
import com.ruoyi.operation.domain.bo.TItdutytaskListBo;
import com.ruoyi.operation.service.ITItdutytaskListService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 生成的任务流水控制器
 * 前端访问路由地址为:/operation/itdutytaskList
 *
 * @author chq
 * @date 2025-07-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/itdutytaskList")
public class TItdutytaskListController extends BaseController {

    private final ITItdutytaskListService iTItdutytaskListService;

    /**
     * 查询生成的任务流水列表
     */
    @SaCheckPermission("operation:itdutytaskList:list")
    @GetMapping("/list")
    public TableDataInfo<TItdutytaskListVo> list(TItdutytaskListBo bo, PageQuery pageQuery) {
        return iTItdutytaskListService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出生成的任务流水列表
     */
    @SaCheckPermission("operation:itdutytaskList:export")
    @Log(title = "生成的任务流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TItdutytaskListBo bo, HttpServletResponse response) {
        List<TItdutytaskListVo> list = iTItdutytaskListService.queryList(bo);
        ExcelUtil.exportExcel(list, "生成的任务流水", TItdutytaskListVo.class, response);
    }

    /**
     * 获取生成的任务流水详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("operation:itdutytaskList:query")
    @GetMapping("/{id}")
    public R<TItdutytaskListVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iTItdutytaskListService.queryById(id));
    }

    /**
     * 新增生成的任务流水
     */
    @SaCheckPermission("operation:itdutytaskList:add")
    @Log(title = "生成的任务流水", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TItdutytaskListBo bo) {
        return toAjax(iTItdutytaskListService.insertByBo(bo));
    }

    /**
     * 修改生成的任务流水
     */
    @SaCheckPermission("operation:itdutytaskList:edit")
    @Log(title = "生成的任务流水", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TItdutytaskListBo bo) {
        return toAjax(iTItdutytaskListService.updateByBo(bo));
    }

    /**
     * 删除生成的任务流水
     *
     * @param ids 主键串
     */
    @SaCheckPermission("operation:itdutytaskList:remove")
    @Log(title = "生成的任务流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iTItdutytaskListService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 根据TItdutytask，每日初始化（全量），插入初始化的TItdutytaskList
     */
//    @SaCheckPermission("operation:itdutytaskList:add")
    @PostMapping("/initDaytask/{dateEight}")
    public TableDataInfo<TItdutytaskListVo> initDaytask(@PathVariable String dateEight) {
        return iTItdutytaskListService.initDaytask(dateEight);
    }

    @SaCheckPermission("operation:itdutytaskList:list")
    @PostMapping("/daily/dutytask")
    public List<DailyTaskVo> dailyDutytask(@Validated @RequestBody DailyTaskBo bo) {
        return iTItdutytaskListService.dailyDutytask(bo);
    }


}
